// localLifePackage/pages/appLocal/appLocal.js
var app = getApp();

var WxParse = require("../../../wxParse/wxParse.js");

var common = require("../../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        agreement: false,
        //协议
        read_check: true
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        let that = this;
        let status = options.status;
        that.setData({
            domain: app.globalData.domain.slice(0, -10),
            status: status
        });
        wx.getSystemInfo({
            success(res) {
                that.setData({
                    imageHeight: res.windowHeight
                });
            }
        });
        that.getBase();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    radiocon: function(e) {
        var check = this.data.read_check;
        check = !check;
        this.setData({
            read_check: check
        });
    },
    toLocalLiving() {
        if (!this.data.read_check) {
            wx.showModal({
                title: "提示",
                content: "请先阅读入驻协议！",
                showCancel: false
            });
        } else {
            wx.navigateTo({
                url: "/localLifePackage/pages/localLiving/localLiving?status=1"
            });
        }
    },
    getStatus: function() {
        var that = this;
        common.request({
            endpoint: "Localbusiness/merchant/merchant-detail",
            method: "post",
            data: {
                user_id: that.data.uid
            },
            success: res => {
                console.log(res);
                let res_status = res.extra ? res.extra.status : 0;
                that.setData({
                    status: res_status
                });
                if (res_status == 2) {
                    wx.navigateTo({
                        url: "/localLifePackage/pages/codeApply/codeApply?name=" + res.extra.name
                    });
                }
            }
        });
    },
    goback: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    reaseApply: function() {
        wx.navigateTo({
            url: "/localLifePackage/pages/localLiving/localLiving?status=1"
        });
    },
    agreementTap: function() {
        var that = this;
        common.request({
            endpoint: "Localbusiness/common/merchant-agreement",
            method: "post",
            data: {},
            success: res => {
                console.log(res);
                if (!res.extra) {
                    res.extra.merchant_agreement = "<p>暂无协议</p>";
                }
                that.setData({
                    agreement: true,
                    agreementText: WxParse.wxParse("agreementText", "html", res.extra.merchant_agreement, that, 0)
                });
            }
        });
    },
    noticeCancel: function() {
        this.setData({
            agreement: false
        });
    },
    //全局基础配置信息
    getBase: function() {
        var that = this;
        common.request({
            endpoint: "set/app_base",
            method: "get",
            data: {},
            success: res => {
                var goodsListStyle = that.data.goodsListStyle;
                wx.setNavigationBarColor({
                    backgroundColor: res.extra.color_main
                });
                that.setData({
                    local_apply_img: res.extra.local_apply_img
                });
                // that.setData({
                //   color_main: res.extra.color_main,
                //   color_minor: res.extra.color_minor,
                //   apptitle: res.extra.title,
                //   style: res.extra.style,
                //   timeStyle: {
                //     height: 32,
                //     mainColor: res.extra.color_main
                //   },
                //   goodsListStyle: {
                //     ...goodsListStyle,
                //     mainColor: res.extra.color_main
                //   }
                // })
                        }
        });
    }
});